/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans.ejb;

import entities.Nflplayer;
import entities.Nflplayergame;
import entities.Week;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author The Lunatics
 */
@Stateless
public class NflplayergameFacade extends AbstractFacade<Nflplayergame> {

    @PersistenceContext(unitName = "Touchdown308PU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public NflplayergameFacade() {
        super(Nflplayergame.class);
    }

    public Nflplayergame findByPlayerByWeek(Nflplayer player, Week week) {
        Query createQuery = getEntityManager().createQuery("SELECT f from Nflplayergame f where f.playerId = :playerId AND f.weekId = :weekId");
        createQuery.setParameter("playerId", player);
        createQuery.setParameter("weekId", week);
        try {
            return (Nflplayergame) createQuery.getSingleResult();
        } catch (NoResultException e) {
            return null;
        }
    }
}
